package com.dc.kylin.timedscheduling.controller;

import com.dc.kylin.timedscheduling.service.SchedulingService;
import com.dc.kylin.timedscheduling.task.ScheduleTask;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private final ScheduleTask scheduleTask;

    @Autowired
    private final SchedulingService schedulingService;

    public TestController(ScheduleTask scheduleTask, SchedulingService schedulingService) {
        this.scheduleTask = scheduleTask;
        this.schedulingService = schedulingService;
    }


    @GetMapping("/updateCron")
    public String updateCron(String cron) {
        log.info("当前参数传入的cron:{}",cron);
        scheduleTask.setCron(cron);
        return "success";
    }


    @GetMapping("/updateCronEx")
    public String updateCronExpression(String cron) {
        log.info("当前updateCronEx请求参数传入的cron:{}",cron);
        schedulingService.updateCronSchedule(cron);
        return "success";
    }
}
